//
//  TJZF_TabBarController.m
//  TJYDZFTerminal
//
//  Created by thinkjoy on 2017/3/10.
//  Copyright © 2017年 杜瑞胜. All rights reserved.
//

#import "TJZF_TabBarController.h"

#import "TJZF_HomePageVC.h"
#import "TJZF_MessageQueryVC.h"
#import "TJZF_MoveZFVC.h"
#import "TJZF_MoveOAVC.h"

@interface TJZF_TabBarController ()<UITabBarControllerDelegate>

@property   (nonatomic,assign)  CGFloat  KWinW;

@property   (nonatomic,strong)  UIColor * normalColor;
@property   (nonatomic,strong)  UIColor * selectColor;

@end

@implementation TJZF_TabBarController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        //        self.tabBar.hidden  =   YES;
        //默认进入的页面   0 首页    1 信息查询  2 移动执法  3 移动OA
        
//        self.selectedIndex  =   3;
    }
    return self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //隐藏导航栏
    [self.navigationController.navigationBar setHidden:YES];
}
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setHidden:NO];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate   =   (id)self;
    self.tabBarController.delegate  =   (id)self;
    
    _KWinW  =   [[UIScreen mainScreen] bounds].size.width;
    
    _normalColor    =   [UIColor lightGrayColor];
    _selectColor    =   [UIColor blueColor];
    
//    UIView * mView=[[UIView alloc]initWithFrame:CGRectMake(0,0,_KWinW,49)];//这是整个tabbar的颜色
//    [mView setBackgroundColor:[UIColor whiteColor]];
//    
//    [self.tabBar insertSubview:mView atIndex:1];
    
    
    TJZF_HomePageVC *   homePageVC  =   [TJZF_HomePageVC new];
    TJZF_MessageQueryVC * messageQueryVC    =   [TJZF_MessageQueryVC new];
    TJZF_MoveZFVC   *   moveZFVC    =   [TJZF_MoveZFVC new];
    TJZF_MoveOAVC   *   moveOAVC    =   [TJZF_MoveOAVC new];

    [self   addOneChildVC:homePageVC title:@"首页" imageName:@"首页" selectedImageName:@"首页-选中"];
    [self   addOneChildVC:messageQueryVC title:@"信息查询" imageName:@"信息查询" selectedImageName:@"信息查询-选中"];
    [self   addOneChildVC:moveZFVC title:@"移动执法" imageName:@"移动执法" selectedImageName:@"移动执法-选中"];
    [self   addOneChildVC:moveOAVC title:@"移动OA" imageName:@"移动OA" selectedImageName:@"移动OA-选中"];
}

/**
 *  添加一个自控制器
 *
 *  @param childVc           子控制器对象
 *  @param title             标题
 *  @param imageName         图标
 *  @param selectedImageName 选中时的图标
 */

- (void)addOneChildVC:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName {
    
    // 设置标题
    childVc.tabBarItem.title = title;
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:_normalColor} forState:UIControlStateNormal];
    [childVc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:_selectColor} forState:UIControlStateSelected];
    childVc.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -4);
    // 设置图标
    childVc.tabBarItem.image    =   [UIImage imageNamed:imageName];
    
    //    // 不要渲染
    UIImage * selectedImage = [[UIImage imageNamed:selectedImageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage =  selectedImage;
//    [UIImage imageNamed:selectedImageName];
    
    // 添加为tabbar控制器的子控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    [nav.navigationBar setShadowImage:[UIImage new]];
    
    nav.navigationBar.barTintColor    =   [UIColor lightGrayColor];
    [nav.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor redColor]}];
    
    [self addChildViewController:nav ];
}

#pragma mark    判断点击的tabbar是否跳入
- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    
    if (viewController == tabBarController.viewControllers[2])
    {

    }
    return YES;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
